package com.jnu.testdrivendevelopment;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditBookActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_book);

        Intent intent=getIntent();
        int position=intent.getIntExtra("position",0);

        EditText editText=findViewById(R.id.edit_book_name);
        String book_name=intent.getStringExtra("book_name");
        if(null!=book_name){
            editText.setText(book_name);
        }

        Button button_ok=findViewById(R.id.yes);
        button_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.putExtra("book_name",editText.getText().toString());
                intent.putExtra("position",position);
                setResult(BookFragment.RESULT_CODE_ADD_DATA,intent);
                EditBookActivity.this.finish();
            }
        });

        Button button_no=findViewById(R.id.no);
        button_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditBookActivity.this.finish();
            }
        });
    }
}